package com.hongtu.brank2.springel;

import org.aspectj.weaver.ast.Expr;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

public class Order {

    private String userId;

    private Integer age;


    private Boolean isNew;

    private LocalDate orderDate;
    private BigDecimal price;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Boolean getNew() {
        return isNew;
    }

    public void setNew(Boolean aNew) {
        isNew = aNew;
    }

    public LocalDate getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(LocalDate orderDate) {
        this.orderDate = orderDate;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public Order(String userId, Integer age, Boolean isNew, LocalDate orderDate, BigDecimal price) {
        this.userId = userId;
        this.age = age;
        this.isNew = isNew;
        this.orderDate = orderDate;
        this.price = price;
    }

    public static void main(String[] args) {
//        ExpressionParser expressionParser = new SpelExpressionParser();
//        Expression expression = expressionParser.parseExpression("price * 0.8");
//        Order order = new Order();
//        order.setPrice(new BigDecimal(10));
//        BigDecimal value = expression.getValue(order, BigDecimal.class);
//        System.out.println(value);
        List<Order> orders = new ArrayList<Order>(){{
            //年龄19，不是新客，周一下单，金额11
            add(new Order("张三",19,false,LocalDate.of(2020,11,9),new BigDecimal(11)));
            //年龄17，是新客，周五下单，金额19
            add(new Order("李四",17,true,LocalDate.of(2020,11,13),new BigDecimal(19)));
            //年龄17，不是新客，周六下单，金额9
            add(new Order("王五",17,true,LocalDate.of(2020,11,14),new BigDecimal(9)));
        }};
    }


    /**
     *
     * @param orders
     * @param filterRule
     * @param settleRule
     * @param expressionCache
     */
    public static void settle(List<Order> orders, List<String>filterRule, String  settleRule, Map<String, Expression> expressionCache){
        Stream<Order> stream = orders.stream();

        for (String rule : filterRule) {

        }
    }
}